package com.zbkj.crmeb.store.model;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zbkj.crmeb.enums.BusinessTypeEnums;
import com.zbkj.crmeb.enums.task.TaskTypeEnums;
import com.zbkj.crmeb.store.FeatureBaseDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.collections.MapUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("eb_relation")
@ApiModel(value="relation对象", description="关联表")
public class Relation extends FeatureBaseDO implements Serializable {
    private static final long serialVersionUID=11234422167856L;

    @ApiModelProperty(value = "主键ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    @ApiModelProperty(value = "业务code")
    private String businessCode;
    @ApiModelProperty(value = "业务类型")
    private String businessType;
    @ApiModelProperty(value = "扩展字段")
    private String feature;
    @ApiModelProperty(value = "子字段值")
    private String subCode;
    @ApiModelProperty(value = "创建时间")
    private Date gmtCreate;
    @ApiModelProperty(value = "修改时间")
    private Date gmtModify;

    @Override
    protected void resetFeature() {
        feature = JSONObject.toJSONString(getFeatureMap());
    }
    @Override
    protected String getFeatureString() {
        return feature;
    }
    public static Relation buildRelation(String businessCode, BusinessTypeEnums businessTypeEnums,String subCode){
        return buildRelation(businessCode,businessTypeEnums, MapUtils.EMPTY_MAP,subCode);
    }
    public static Relation buildRelation(String businessCode, BusinessTypeEnums businessTypeEnums,Map<String,String> featureMap,String subCode){
        Relation relation = new Relation();
        relation.setBusinessCode(businessCode);
        relation.setBusinessType(businessTypeEnums.getCode());
        relation.addFeatureMap(featureMap);
        relation.setSubCode(subCode);
        relation.setGmtCreate(new Date());
        relation.setGmtModify(new Date());
        return relation;
    }

}